package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 插入菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void Insert(Dish dish);



    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 根据id查询菜品
     * @param dishId
     */
    @Select("select * from dish where id =#{dishId}")
    Dish getByIds(Long dishId);


    /**
     * 根据主键id删除菜品
     * @param id
     */
    @Delete("delete from dish where id = #{id}")
    void DeleteById(Long id);


    //批量删除
    void deleteByIds(List<Long> ids);


    // 更新菜品
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

//  根据套餐分类id查询菜品
    List<Dish> getDishByCategoryId(Dish dish);

    // 根据套餐id查询菜品
    @Select("select d.* from dish d left join sky.setmeal_dish sd on d.id = sd.dish_id where sd.setmeal_id=#{id} ")
    List<Dish> getBySetMealId(Long id);
}
